//导入request.js请求工具
import request from '@/utils/request.js'

//管理员登录
export const adminLoginService = (loginData) => {
    return request.post('/admin/login', loginData)
}

// 获取剧本分页列表
export const getPageScripts = (params) => {
    return request.post('/admin/scripts/page', params)
}

// 保存剧本（新增和修改统一接口）
export const saveScript = (scriptData) => {
    return request.post('/admin/scripts/save', scriptData)
}

// 更新剧本（保留原有接口名，但使用统一接口）
export const putScript = (scriptData) => {
    return request.post('/admin/scripts/save', scriptData)
}

// 删除剧本
export const deleteScript = (scriptId) => {
    return request.delete(`/admin/scripts/${scriptId}`)
}

// 根据标签名获取标签列表
export const getTagsByName = (name) => {
    return request.get('/admin/tags/getTagsByName', { params: { name } })
}

// 文件上传
export const uploadFile = (file) => {
    const formData = new FormData()
    formData.append('file', file)
    return request.post('/admin/upload/file', formData, {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

// 根据分类名获取分类列表
export const getCategoriesByName = (name) => {
    return request.get('/admin/categories/getByName', { params: { name } })
}

// 获取所有分类列表
export const getAllCategories = () => {
    return request.get('/admin/categories/list')
}

// 获取分类分页列表
export const getPageCategories = (params) => {
    return request.get('/admin/categories/page', { 
        params: {
            name: params.name || '',
            page: params.pageNo || 1,
            pageSize: params.pageSize || 10
        }
    })
}

// 根据ID获取分类详情
export const getCategoryById = (id) => {
    return request.get(`/admin/categories/${id}`)
}

// 新增分类
export const addCategory = (categoryData) => {
    return request.post('/admin/categories', categoryData)
}

// 更新分类
export const updateCategory = (categoryData) => {
    return request.put('/admin/categories', categoryData)
}

// 删除分类
export const deleteCategory = (categoryId) => {
    return request.delete(`/admin/categories/${categoryId}`)
}

// 标签管理接口
export const getTagList = (params) => {
  return request({
    url: '/admin/tags/getTagsPage',
    method: 'get',
    params
  })
}

export const saveTag = (data) => {
  return request({
    url: '/admin/tags/save',
    method: 'post',
    data
  })
}

export const updateTag = (data) => {
  return request({
    url: '/admin/tags/upDataTags',
    method: 'put',
    data
  })
}

export const deleteTag = (id) => {
  return request({
    url: `/admin/tags/deleteTags/${id}`,
    method: 'delete'
  })
}

export const getAllTags = () => {
  return request({
    url: '/admin/tags/getTagsName',
    method: 'get'
  })
}

